import { defineStore } from 'pinia'
import { reactive, computed } from "vue";
export const useStore = defineStore('menu', () => {
  const state = reactive({
    // 菜单已加载
    menu_loaded: false,
    // 菜单列表
    menu_list: [],
    // 所有菜单项
    all: [],
    // 权限已加载
    auth_loaded: false,
    // 权限列表
    auths: [],
  } as {
    menu_loaded: boolean,
    menu_list: any[],
    all: any[],
    auth_loaded: boolean,
    auths: string[],
  })
  // 全部加载完成
  const loaded = computed(() => {
    return state.menu_loaded && state.auth_loaded;
  })
  // 菜单加载完成
  const menuLoaded = () => {
    state.menu_loaded = true;
  }
  // 设置菜单列表
  const setMenuList = (e: any[]) => {
    state.menu_list = e;
  }
  // 设置所有菜单项
  const setAll = (e: any[]) => {
    state.all = e;
  }
  // 权限加载完成
  const authLoaded = (bool: boolean) => {
    state.auth_loaded = bool;
  }
  // 设置权限列表
  const setAuths = (e: any[]) => {
    state.auths = e;
  }
  return {
    state,
    menuLoaded,
    authLoaded,
    loaded,
    setMenuList,
    setAll,
    setAuths,
  }
})
